using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace Bordecal.ImportsSorter.Properties
{
	internal static class TemplatedResources
	{
		/// <summary>
		/// Prepares the localized message to be used for confirming deletion of a list item.
		/// </summary>
		/// <param name="itemText">The display text of the item selected for deletion.</param>
		/// <returns>The localized message.</returns>
		[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
		internal static string DeleteListItemConfirmation(string itemText)
		{
			return string.Format(CultureInfo.CurrentCulture,
				Resources.DeleteListItemConfirmation,
				itemText);
		}

		/// <summary>
		/// Prepares the localized message to be displayed when a list fails validation due to duplicates.
		/// </summary>
		/// <param name="duplicates">The list of duplicates found in the validated list.</param>
		/// <returns>The localized message.</returns>
		internal static string DuplicatesInListValidationMessage(string[] duplicates)
		{
			return string.Format(CultureInfo.CurrentCulture,
				Resources.ValidationError_DuplicatesInList,
				string.Join(Environment.NewLine, duplicates));
		}

		/// <summary>
		/// Prepares the localized message to be displayed when a list fails validation due to an
		/// excessive number of list items.
		/// </summary>
		/// <param name="maxCount">The maximum number of items allowed in the list.</param>
		/// <returns>The localized message.</returns>
		internal static string ListTooLongValidationMessage(int maxCount)
		{
			return string.Format(CultureInfo.CurrentCulture,
				Resources.ValidationError_ListTooLong,
				maxCount);
		}


		/// <summary>
		/// Prepares the localized message to be displayed when a number falls outside
		/// a permitted inclusive range.
		/// </summary>
		/// <param name="allowedRange">The range of allowed values.</param>
		/// <returns>The localized message.</returns>
		internal static string OutOfInclusiveRangeValidationMessage<T>(Range<T> allowedRange) where T : struct, IComparable<T>
		{
			return string.Format(CultureInfo.CurrentCulture,
				Resources.ValidationError_OutOfInclusiveRange,
				allowedRange.Minimum, allowedRange.Maximum);
		}

		/// <summary>
		/// Prepares the localized string to be displayed as the name of the undo context
		/// for the imports/using directives sorting operation.
		/// </summary>
		/// <param name="language">The language of the code file against which the sorting has been applied.</param>
		/// <returns>The localized label for the undo context.</returns>
		internal static string UndoContextName(LanguageType language)
		{
			return string.Format(CultureInfo.CurrentCulture,
				Resources.UndoContextName,
				ImportsDirectiveName(language));
		}

		/// <summary>
		/// Prepares the localized string to be displayed as the shortcut menu command label
		/// for the imports/using directive sorting command button.
		/// </summary>
		/// <param name="language">The language of the code file against which the menu is being displayed.</param>
		/// <returns>The localized label for the command button.</returns>
		internal static string SortingCommandText(LanguageType language)
		{
			return string.Format(CultureInfo.CurrentCulture,
				Resources.SortingCommandText,
				ImportsDirectiveName(language));
		}

		/// <summary>
		/// Prepares the localized string to be displayed as the shortcut menu command description
		/// for the imports/using directive sorting command button.
		/// </summary>
		/// <param name="language">The language of the code file against which the menu is being displayed.</param>
		/// <returns>The localized description for the command button.</returns>
		internal static string SortingCommandDescription(LanguageType language)
		{
			return string.Format(CultureInfo.CurrentCulture,
				Resources.SortingCommandDescription,
				ImportsDirectiveName(language));
		}

		/// <summary>
		/// Determines the localized name for an imports/using directive in a given code language.
		/// </summary>
		/// <param name="language">The code language for which the imports/using directive name is to be found.</param>
		/// <returns>The localized name for an imports/using directive.</returns>
		private static string ImportsDirectiveName(LanguageType language)
		{
			string languageName = LanguageType.Unknown.ToString();
			switch (language)
			{
				case LanguageType.CSharp:
				case LanguageType.VisualBasic:
				case LanguageType.CPlusPlus:
				case LanguageType.JSharp:
					languageName = language.ToString();
					break;
			}

			return Resources.ResourceManager.GetString("ImportDirectiveName_" + languageName, Resources.Culture);
		}
	}
}